Page({

  data: {

  },

  onLoad: async function (options) {
    var { url } = options;
    console.log(url);
    if (url == ":3000/top/playlist/highquality") {
      var url = "http://47.108.197.28" + url;
      wx.request({
        url,
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (res) => {
          var playlists = res.data.playlists;
          var list = []
          playlists.forEach(item => {
            var { coverImgUrl, name, id, playCount } = item;
            list.push({
              coverImgUrl,
              name,
              id,
              playCount
            })
            this.setData({
              list
            })
          })
        },


      });
    } else if (url == ":3000/personalized/djprogram") {
      var url = "http://47.108.197.28" + url;
      wx.request({
        url,
        data: {},
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (res) => {
          var result = res.data.result;
          var list = []
          result.forEach(item => {
            var { name, id, picUrl } = item;
            list.push({
              name,
              playCount: id,
              coverImgUrl: picUrl
            })
            this.setData({
              list
            })
          })
        }
      })
    } else {
      var url = "http://47.108.197.28" + url;
      wx.request({
        url,
        data: {},
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (res) => {
          var albums = res.data.albums;
          var list = []
          albums.forEach(item => {
            var { picUrl, name, copyrightId, id } = item;
            list.push({
              coverImgUrl: picUrl,
              name,
              playCount: copyrightId,
              id
            })
            this.setData({
              list
            })
          })
        }
      })
    }

  },
  handleClick(event) {
    var {aid} = event.currentTarget.dataset
    wx.navigateTo({
      url:`/pages/detailId/detailId?id=${aid}`
  })
}

})
